/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyecto.so1;

import java.net.*;
import java.io.*;

/**
 *
 * @author edwin
 */
public class State extends Thread implements Runnable{
    
    private boolean execute;
    private int port;
    
    public State(){
        execute = true;
        port = 10000;
    }
    
    
    @Override
    public void run(){
        try{
            ServerSocket server = new ServerSocket(port, 0, NetworkInterface.getByName("eth0").getInterfaceAddresses().get(1).getAddress());
            server.setReuseAddress(true);
            while(execute){
                Socket client = server.accept();
                OutputStream output = client.getOutputStream();
                DataOutputStream data = new DataOutputStream(output);
                data.writeBoolean(principal.state);
                client.close();
            }
        }
        catch(UnknownHostException uhe){ System.err.println(uhe.getMessage()); }
        catch(SocketException se){ System.err.println(se.getMessage()); }
        catch(IOException ioe){ System.err.println(ioe.getMessage()); }
    }
}
